package com.ruoyi.web.controller.mdm;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mdm.domain.WeightRule;
import com.ruoyi.mdm.service.IWeightRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 权重规则Controller
 *
 * @author shiseido
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/mdm/weightRule")
public class WeightRuleController extends BaseController {
    @Autowired
    private IWeightRuleService weightRuleService;

    /**
     * 查询权重规则列表
     */
    @ApiOperation("查询权重规则列表")
    @PreAuthorize("@ss.hasPermi('mdm:weightRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(WeightRule weightRule) {
        startPage();
        List<WeightRule> list = weightRuleService.selectWeightRuleList(weightRule);
        return getDataTable(list);
    }

    /**
     * 导出权重规则列表
     */
    @ApiOperation("导出权重规则列表")
    @PreAuthorize("@ss.hasPermi('mdm:weightRule:export')")
    @Log(title = "权重规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WeightRule weightRule) {
        List<WeightRule> list = weightRuleService.selectWeightRuleList(weightRule);
        ExcelUtil<WeightRule> util = new ExcelUtil<WeightRule>(WeightRule.class);
        util.exportExcel(response, list, "权重规则数据");
    }

    /**
     * 获取权重规则详细信息
     */
    @ApiOperation("获取权重规则详细信息")
    @PreAuthorize("@ss.hasPermi('mdm:weightRule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(weightRuleService.selectWeightRuleById(id));
    }

    /**
     * 新增权重规则
     */
    @ApiOperation("新增权重规则")
    @PreAuthorize("@ss.hasPermi('mdm:weightRule:add')")
    @Log(title = "权重规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WeightRule weightRule) {
        return toAjax(weightRuleService.insertWeightRule(weightRule));
    }

    /**
     * 修改权重规则
     */
    @ApiOperation("修改权重规则")
    @PreAuthorize("@ss.hasPermi('mdm:weightRule:edit')")
    @Log(title = "权重规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WeightRule weightRule) {
        return toAjax(weightRuleService.updateWeightRule(weightRule));
    }

    /**
     * 删除权重规则
     */
    @ApiOperation("删除权重规则")
    @PreAuthorize("@ss.hasPermi('mdm:weightRule:remove')")
    @Log(title = "权重规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(weightRuleService.deleteWeightRuleByIds(ids));
    }
}
